package la.iok.hzsvn.lewin.movie.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.core.movieservice.vo.MovieLevelVo;
import la.iok.hzsvn.lewin.movie.model.MovieLevelParam;
import la.iok.hzsvn.lewin.movie.service.MovieLevelService;
import la.iok.hzsvn.share.response.ListDataResponse;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("movieLevels")
public class MovieLevelController {
    private final MovieLevelService movieLevelService;

    public MovieLevelController(MovieLevelService movieLevelService) {
        this.movieLevelService = movieLevelService;
    }
    @GetMapping
    public ListDataResponse<MovieLevelVo> list(){
        return new ListDataResponse<>(movieLevelService.po2vo(movieLevelService.selectAll()));
    }
    @PostMapping
    public OperatorResponse save(@RequestHeader Token token, @RequestBody MovieLevelParam param){
        movieLevelService.save(token,param);
        return OperatorResponses.success();
    }
    @DeleteMapping("{id}")
    public OperatorResponse delete(@RequestHeader Token token, @PathVariable Long id){
        movieLevelService.delete(token,id);
        return OperatorResponses.success();
    }
    @PutMapping("{id}")
    public OperatorResponse modify(@RequestHeader Token token, @PathVariable Long id,@RequestBody MovieLevelParam param){
        movieLevelService.update(token,id,param);
        return OperatorResponses.success();
    }
}
